package yu.zhu.top.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author yuzhu
 * @Date 2020/11/14 16:37
 */
@Configuration
public class DirectRabbitConfig {
    //队列 起名：TestDirectQueue
    @Bean
    public Queue felixQueueMysql() {

        return new Queue("top_spiders_Mysql",true);
    }

    /**
     *创建2个队列
     * @return
     */
    @Bean
    public Queue felixQueueRedis(){
        return new Queue("top_spiders_Redis",true);
    }

    @Bean
    public Queue felixQueueMongoDB() {
        return new Queue("top_spiders_MongoDB",true);
    }
    @Bean
    public Queue felixQueueES() {
        return new Queue("top_spiders_ES",true);
    }
    /**
     * @Title 声明一个Fanout类型的交换机
     * @Description Fanout类型的交换机会将消息分发到所有的绑定队列，没有RoutingKey的概念
     **/

    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("top_spiders_Exchange");
    }


    @Bean
    Binding bindingExchangeMysql(Queue felixQueueMysql, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(felixQueueMysql).to(fanoutExchange);
    }
    @Bean
    Binding bindingExchangeRedis(Queue felixQueueRedis, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(felixQueueRedis).to(fanoutExchange);
    }
    @Bean
    Binding bindingExchangeMongoDB(Queue felixQueueMongoDB, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(felixQueueMongoDB).to(fanoutExchange);
    }
    @Bean
    Binding bindingExchangeES(Queue felixQueueES, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(felixQueueES).to(fanoutExchange);
    }


}
